<?php
require_once(APPPATH.'views/components/page.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<link href='<?php echo base_url() ?>resources/css/admin.css' rel='stylesheet' type='text/css' />
		<script src="<?php echo base_url() ?>resources/js/jquery-1.4.2.min.js"></script>
		<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
		
		<script type="text/javascript">
			function onSaveBtnClicked()
			{
				var branchName = document.getElementById("branchname").value;
				branchName = branchName.trim();
				
				if (branchName.length == 0)
				{
					alert("Vui lòng nhập tên Xuất xứ");
					return false;
				}
				
				return true;
			}
			
			function onCancelBtnClicked(baseurl)
			{
				window.location = baseurl + "branch";
			}
		</script>
		
		<title>Cập nhật xuất xứ</title>
	</head>
	
	<body>
		<div id='wrapper'>
			<div id='header'>
				<div id="leftTopPan">
				<a href='<?php echo base_url() ?>'><img src='<?php echo base_url() ?>resources/images/logo.gif' title='Consultant' alt='Consultant' width='160' height='39' border='0' /></a>
				</div>
				<h1></h1>
			</div>
			<div id="middle">
				<div id="container">
					<div id="content">
						<br /><h2 align="center">Cập nhật xuất xứ</h2><br />
						
						<?php
						
						// Error handler
						$error = $this->session->userdata('error');
						$this->session->unset_userdata('error');
						
						if (isset($rerror))
							$error = $rerror;
						
						$errorText = "";
						
						switch ($error) {
							case UPDATE_ERROR:
								$errorText = sprintf(UPDATE_ERROR_TEXT, 'Xuất xứ');
								break;
							case EXISTED_ERROR:
								$name = $this->session->userdata('branchname');
								$this->session->unset_userdata('branchname');
								$errorText = sprintf(EXISTED_ERROR_TEXT, "Xuất xứ", $name);
								break;
							case NOT_EXISTED_ERROR:
								$errorText = NOT_EXISTED_ERROR_TEXT;
								break;
							default:
								break;
						}
						?>
						<h3 style="color: red"><?php echo $errorText ?></h3>
						<?php
						
						
						$userdata = $this->session->userdata('userdata');
						
						if (Page::getInstance()->isAdmin() && $branch->getId() > 0)
						{
							// User information
							Page::getInstance()->generateUserInfo($userdata);
							
							// Begin edit form
							echo form_open('branch/update');
							
							// Hiddenn form
							echo form_hidden('branchid', $branch->getId());
							
							// Text box
							$titleTxt = array(	'id'		=>	'branchname',
												'name'		=>	'branchname',
												'value'		=>	$branch->getName());
						?>
						<p>Xuất xư: <?php echo form_input($titleTxt) ?></p>
							
						<?php
							// Save button
							$saveBtn = array(	'id'		=>	'savebtn',
												'name'		=> 	'savebtn',
												'value'		=>	'Lưu',
												'onclick'	=>	'return onSaveBtnClicked()');
							echo form_submit($saveBtn);
							
							// Reset button
							$cancelBtn = array(	'id'		=> 'cancelbtn',
												'name'		=> 'cancelbtn',
												'value'		=> 'Hủy',
												'onclick'	=> "onCancelBtnClicked('".base_url()."')");
							echo form_reset($cancelBtn);
							
							// End edit form
							echo form_close();
						}
						?>
					</div>
				</div>
					<?php
						if (Page::getInstance()->isAdmin())
						{
							Page::getInstance()->generateAdminLeftMenu();
						}
					?>
			</div>
		</div>
		
	</body>
</html>